package cloud.keveri.springboot.starter.gateway.plugin.global;

import cloud.keveri.gateway.dto.IDefinitionDynamicManager;
import cloud.keveri.gateway.plugin.api.KeveriPlugin;
import cloud.keveri.gateway.plugin.api.context.GatewayContextBuilder;
import cloud.keveri.gateway.plugin.global.DefaultGatewayContextBuilder;
import cloud.keveri.gateway.plugin.global.GlobalPlugin;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 * 作者：沈自在
 **/
@Configuration
@ConditionalOnClass(GlobalPlugin.class)
public class GatewayPluginGlobalAutoConfiguration {

    /**
     *
     */
    @Bean
    public GatewayContextBuilder gatewayContextBuilder(ObjectProvider<IDefinitionDynamicManager> definitionDynamicManagers) {
        return new DefaultGatewayContextBuilder(definitionDynamicManagers.getIfAvailable());
    }

    /**
     *
     */
    @Bean
    public KeveriPlugin globalPlugin(GatewayContextBuilder gatewayContextBuilder) {
        return new GlobalPlugin(gatewayContextBuilder);
    }
}
